//
//  MoreViewController.m
//  SXH
//
//  Created by 房 国生 on 15/6/25.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "MoreViewController.h"
#import "MoreTableViewCell.h"
#import "SuggestViewController.h"
#import "CommonService.h"
#import "WebViewController.h"
#import "SocialViewController.h"
@interface MoreViewController ()
@property (strong, nonatomic) IBOutlet UIView *introTableView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewMore;
@property (nonatomic, strong) NSString *appURL;
@end

@implementation MoreViewController
@synthesize tableViewMore, mutableArrayMore;
@synthesize mainVC, wrapperMainVC;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableViewMore.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.scrollViewMore addSubview:self.introTableView];
    // Do any additional setup after loading the view from its nib.
    NSString *path = [[NSBundle mainBundle] pathForResource:@"More" ofType:@"plist"];
    mutableArrayMore = [[NSMutableArray alloc] initWithContentsOfFile:path];
    
    [self.tableViewMore.layer setMasksToBounds:YES];
    [self.tableViewMore.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
    [self.tableViewMore.layer setBorderWidth:1.0]; //边框宽度
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 0.77, 0.77, 0.77, 1 });
    [self.tableViewMore.layer setBorderColor:colorref];//边框颜色
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [mutableArrayMore count];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *couponTableViewCellIdentifier=@"MoreTableViewCell";
    MoreTableViewCell *cell = (MoreTableViewCell *)[tableView dequeueReusableCellWithIdentifier:couponTableViewCellIdentifier];
    if (cell == nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MoreTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSDictionary *dic = [mutableArrayMore objectAtIndex:indexPath.row];
    cell.imageViewIcon.image = [UIImage imageNamed:[dic valueForKeyPath:@"icon"]];
    cell.labelName.text = [dic valueForKeyPath:@"name"];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //NewsEntity *entity = [arraySpot objectAtIndex:indexPath.row];
    if (indexPath.row == 2)
    {
        SuggestViewController *vc = [[SuggestViewController alloc] init];
        if (mainVC != nil) {
            [self.navigationController pushViewController:vc animated:YES];
        } else {
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    else if (indexPath.row == 3)
    {
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/le-you-lu-you-dao-lan-lu-you/id1028933543?l=en&mt=8"]];
    }
    else if (indexPath.row == 4)
    {
        WebViewController *vc = [[WebViewController alloc] init];
        vc.url = @"http://api.leyouss.com/user_protocol.html";
        vc.vcTitle = @"协议";
        vc.shareBtn.hidden = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 1)
    {
        UIImage *imageIcon = [UIImage imageNamed:@"icon"];
        NSArray *imageArray = [[NSArray alloc]initWithObjects:imageIcon, nil];
        [CommonService showShareActionSheet:self.view HUD:HUD
                                 ImageArray:imageArray
                                        URL:PORTAL_URL
                                      Title:AppName
                                    Content:@"乐游山水APP-您口袋里的智能语音导览助手"];
    } else if (indexPath.row == 0)
    {
        WebViewController *vc = [[WebViewController alloc] init];
        vc.url = [NSString stringWithFormat:@"%@%@", BASEURL,SOFT_INTRODUCE];
        vc.vcTitle = @"功能介绍";
        vc.shareBtn.hidden = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 5)
    {
        SocialViewController *vc = [[SocialViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (IBAction)doBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (alertView.tag == 90000) {
        if (buttonIndex == 1) {
            NSURL *url = [NSURL URLWithString:super.appURL];
            [[UIApplication sharedApplication]openURL:url];
        }
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"MoreViewController"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"MoreViewController"];
}
@end




